package com.demo.service.impl;

import com.demo.domain.URLEntity;
import com.demo.dto.response.URLGetResponse;
import com.demo.dto.response.URLIndexResponse;
import com.demo.mapper.URLMapper;
import com.demo.service.SearchBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2016/4/29.
 */
@Service
public class SearchBaseServiceImpl implements SearchBaseService {

    @Autowired
    URLMapper urlDao;

    @Override
    public URLIndexResponse URLIndex(URLEntity url) {
        urlDao.insertURL(url);
        return new URLIndexResponse(true, "返回值");
    }

    @Override
    public URLGetResponse URLGet(String id) {
        URLEntity urlEntity = urlDao.selectURL(id);
        String result;
        if (urlEntity == null)
        {
            result = "没有找到";
        } else {
            result = urlEntity.getId() + "/" + urlEntity.getUrl();
        }
        return new URLGetResponse(true, result);
    }

    @Override
    public List<URLEntity> URLGets() {
        return urlDao.selectURLs();
    }

    @Override
    public void URLDelete(String id) {
        urlDao.deleteURL(id);
    }

    @Override
    public void URLUpdate(URLEntity url) {
        urlDao.updateURL(url);
    }


}
